using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using Acms.SqlDal;

namespace Acms.Bll
{
    public class PostControl : BaseItem
    {
        private PostControl() : base() { }
        private PostControl(Hashtable table) : base(table) { }
        private PostControl(Hashtable table, List<PostControl> collection) : base(table, collection) { }

        protected override Base CreateDal()
        {
            return new PostControlDal();
        }

        public static PostControl CreateInstance()
        {
            return new PostControl();
        }

        private static PostControl Get(Hashtable table)
        {
            if (table != null)
            {
                return new PostControl(table);
            }
            else
            {
                return null;
            }
        }

        private static List<PostControl> Get(Hashtable[] tables)
        {
            if (tables != null)
            {
                List<PostControl> tmp = new List<PostControl>();
                foreach (Hashtable table in tables)
                {
                    tmp.Add(new PostControl(table, tmp));
                }
                return tmp;
            }
            else
            {
                return null;
            }
        }

        public static List<PostControl> GetAllByPostId(int postId)
        {
            PostControlDal dal = new PostControlDal();
            return Get(dal.GetAllByPostId(postId));
        }

        public static PostControl GetByPostIdAndTemplateControlId(int postId, int templateControlId)
        {
            PostControlDal dal = new PostControlDal();
            return Get(dal.GetByPostIdAndTemplateControlId(postId, templateControlId));
        }

        public static List<PostControl> GetAllBySiteIdAndTypeName(int siteId, string typeName)
        {
            PostControlDal dal = new PostControlDal();
            return Get(dal.GetAllBySiteIdAndTypeName(siteId, typeName));
        }

        public new void Update()
        {
            base.Update();
        }

        protected override void SaveChanges(ref object concurencyId, Base dal)
        {
            ((PostControlDal)dal).Update(ref id, postId, templateControlId, value, ref concurencyId);
        }
        
        public new void Delete()
        {
            base.Delete();
        }

        protected override void DeleteRecord(object concurencyId, Base dal)
        {
            ((PostControlDal)dal).Delete(id, concurencyId);
        }

        protected override void Load(Hashtable table)
        {
            id = (int)table[PostControlDal.Fields.Id];
            postId = (int)table[PostControlDal.Fields.PostId];
            templateControlId = (int)table[PostControlDal.Fields.TemplateControlId];
            name = (string)table[PostControlDal.Fields.Name];
            typeId = (int)table[PostControlDal.Fields.TypeId];
            typeName = (string)table[PostControlDal.Fields.TypeName];
            adminControlType = (string)table[PostControlDal.Fields.AdminControlType];
            value = (System.Xml.XmlDocument)table[PostControlDal.Fields.Value];
        }

        private int id;
        public int Id
        {
            get { return id; }
        }

        private int postId;
        public int PostId
        {
            get { return postId; }
        }

        private int templateControlId;
        public int TemplateControlId
        {
            get { return templateControlId; }
        }

        private string name;
        public string Name
        {
            get { return name; }
        }
        
        private int typeId;
        public int TypeId
        {
            get { return typeId; }
        }

        private string typeName;
        public string TypeName
        {
            get { return typeName; }
        }

        private string adminControlType;
        public string AdminControlType
        {
            get { return adminControlType; }
        }

        private System.Xml.XmlDocument value;
        public System.Xml.XmlDocument Value
        {
            get { return this.value; }
            set { this.value = value; }
        }
    }
}
